/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.guide.web;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.guide.entity.MobileLabel;
import com.jeeplus.modules.guide.entity.MobileMatterLabel;
import com.jeeplus.modules.guide.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;

/**
 * 高新智能导办-首页-标签绑定搜索
 * Controller
 * @author azj
 * @version 2021-5-15
 */
@RestController
@RequestMapping("/mobileItem")
@RequiredArgsConstructor
public class MobileItemController extends BaseController {
	private final MobileItemService mobileItemService;
	private final VersionService versionService;

	/**
	 * getMatterLabelList 获取事项标签集合展示
	 * matterName事项名称getMatterTop
	 * label标签
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="getMatterLabelList")
	public AjaxJson getMatterLabelList(String matterName,String label,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<>();
		map.put("curPage",pageNo);
		map.put("pageSize",pageSize);
		if(StringUtils.isNotBlank(matterName))
			matterName = "%"+matterName+"%";
		map.put("matterName",matterName);
		if(StringUtils.isNotBlank(label))
			label = "%"+label+"%";
		map.put("label",label);
		map.put("version",versionService.getVersion());
		return AjaxJson.success("事项加载成功！").put("data", mobileItemService.getMatterLabelList(map));
	}

	/**
	 * deleteMatterLabelList 删除事项标签
	 * id标签id
	 * @author azj
	 * @version 2020-04-24
	 */
	@GetMapping(value ="deleteMatterLabel")
	public AjaxJson deleteMatterLabel(String id) {
		mobileItemService.deleteMatterLabel(id);
		return AjaxJson.success("操作成功！");
	}

	/**
	 * inserItem 新增标签
	 * mobileMatterLabel标签类
	 * @author azj
	 * @version 2020-04-24
	 */
	@PostMapping(value ="inserItem")
	public AjaxJson inserItem(MobileMatterLabel mobileMatterLabel) {
		mobileItemService.inserItem(mobileMatterLabel);
		return AjaxJson.success("操作成功！");
	}

	/**
	 * inserItem 新增标签
	 * mobileMatterLabel标签类
	 * @author azj
	 * @version 2020-04-24
	 */
	@PostMapping(value ="updateItem")
	public AjaxJson updateItem(MobileMatterLabel mobileMatterLabel) {
		mobileItemService.updateItem(mobileMatterLabel);
		return AjaxJson.success("操作成功！");
	}

	/**
	 * inserItem 新增事项标签绑定
	 * ids事项集合
	 * id标签id
	 * label标签名称
	 * @author azj
	 * @version 2020-04-24
	 */
	@PostMapping(value ="inserMatterItem")
	public AjaxJson inserMatterItem(String ids,String label,String id) {
		mobileItemService.inserMatterItem(ids,label,id);
		return AjaxJson.success("操作成功！");
	}

	/**
	 * findLabel 查询标签
	 * id标签id
	 * @author azj
	 * @version 2020-04-24et
	 */
	@GetMapping(value ="findLabel")
	public AjaxJson findLabel(String id) {
		return AjaxJson.success("操作成功！").put("data",mobileItemService.findLabel(id));
	}

	/**
	 * findMatterLabel 首页搜索关键词集合加载
	 *
	 * @author azj
	 * @version 2020-04-24et
	 */
	@GetMapping(value ="findMatterLabel")
	public AjaxJson findMatterLabel() {
		return AjaxJson.success("操作成功！").put("data",mobileItemService.findMatterLabel());
	}


	/**
	 * findMatterLabel 添加关键词搜索事项记录
	 * MobileLabel表
	 * @author azj
	 * @version 2020-04-24et
	 */
	@PostMapping(value ="insertMatterLabel")
	public AjaxJson insertMatterLabel(@RequestBody MobileLabel ml) {
		if(StringUtils.isNotBlank(ml.getLabel()) && StringUtils.isNotBlank(ml.getOid())){
			mobileItemService.insertMatterLabel(ml.getOid(),ml.getLabel());
		}
		return AjaxJson.success("操作成功！");
	}

}
